const MAX_TODOS_RUNNING = 5;

var runningTodos = [];
var todoPoolCount = 0;

window.addEventListener( "load", main, false );

function main( )
{
	$('tdt-timer-icon').addEventListener( 'click', tdt_handleTimerPanel, false );
//	var todo1 = new Todo( 1, 1, "alasldalsdla", "sdgsdfg", rightnow( ), 0, "5025000", 2 );
//	var todo2 = new Todo( 2, 1, "alasldalsdla", "aslkjdslkasd", rightnow( ), 0, 0, 2 );
}

function tdt_handleTimerPanel( event )
{
	if( event.button == 0 )
	{
		tdt_startTodo( );
	}
	else if( event.button == 2 )
	{
//		toggleDisplay(  )
//		alert( 'asd' );
//		$('tdt-timer-main').showPopup( $( 'statusscicalc_ico'), -1, -1, "popup", "topleft", "bottomleft" );
	}
}

function tdt_startTodo( )
{	
	if( todoPoolCount >= MAX_TODOS_RUNNING )
	{
		alert( 'You need more ?! Really ? \nCheck the options.' );
		return;
	}
	
	var params = { runningTodos: runningTodos, action : null, selected : {} }; 
	var win = window.openDialog( "chrome://todotime/content/todoDialog.xul", "tdt-select-todo", "chrome,resizable,modal,centerscreen", params );
	
	var todoID = params.todoID;
	if( typeof todoID != 'undefined' )
	{
		Log.debug( 'Selected Todo id '+ todoID  );
		if( ! in_array( todoID, runningTodos ) )
		{
			Timer( tdt_getTodoById( todoID ) );
			runningTodos.push( todoID );
		}
	}	
}